package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.enterprise.CopyrightListEntity2;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.swgk.core.event.EventConstant;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class IpCopyrightAdapter extends BaseRecycleAdapter<CopyrightListEntity2> {
    Context context;
    TextView tv_tag;

    public IpCopyrightAdapter(Context context, List<CopyrightListEntity2> datas) {
        super(context, R.layout.item_ip_copyright, datas);
        this.context = context;
    }

    @Override
    public void convert(ItemViewHolder holder, CopyrightListEntity2 copyrightListEntity2) {
        holder.setBinding(BR.viewModel, copyrightListEntity2);
        tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (copyrightListEntity2.getPublishType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }
        if (copyrightListEntity2.getLabel() != null && copyrightListEntity2.getLabel().contains("1")) {
            holder.setVisible(R.id.tv_item_intel_prop_hot, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_hot, false);
        }
        if (copyrightListEntity2.getLabel() != null && copyrightListEntity2.getLabel().contains("2")) {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, true);
        } else {
            holder.setVisible(R.id.tv_item_intel_prop_urgent_sale, false);
        }

        holder.getItem().findViewById(R.id.btn_chat).setOnClickListener(view -> {
            if (DialogHelper.checkLogin()) {
                DialogHelper.showDialog(context, "确认呼叫", copyrightListEntity2.getContacts() + ":" + copyrightListEntity2.getContactNumber(), "确定", new DialogFunction() {
                    @Override
                    public void normalRoundDialog() {
                        ActivityJump.jumpToPhone(context, copyrightListEntity2.getContactNumber());
                    }
                });
            } else {
                DialogHelper.showLoginDialogNew(context, EventConstant.EVENT_INTELL_PROP_FRG_JUMP, "温馨提示", "登录后可拨打电话,去登录", "登录");
            }

        });
        ImageView roundImageView = holder.getItem().findViewById(R.id.logo_view);

        if (copyrightListEntity2.getImg() != null && !copyrightListEntity2.getImg().equals("")) {
            Glide.with(context).load(copyrightListEntity2.getImg()).apply(RequestOptions.bitmapTransform(new RoundedCorners(2))).into(roundImageView);
        } else {
            roundImageView.setImageResource(R.mipmap.morentu_change);
        }
    }


}
